package com.ruoyi.job.task;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadChi {
    public static void main(String[] args) {
        // 创建一个固定大小的线程池，大小为2
        ExecutorService executor = Executors.newFixedThreadPool(2);

        // 创建两个线程实例
        Thread thread1 = new Thread(new MyRunnable("Thread 1"));
        Thread thread2 = new Thread(new MyRunnable("Thread 2"));

        // 将线程加入线程池并执行
        executor.execute(thread1);
        executor.execute(thread2);

        // 关闭线程池
        executor.shutdown();
    }
}

class MyRunnable implements Runnable {
    private String name;

    public MyRunnable(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        System.out.println(name + " is running.");
    }
}

